package com.zb.emq;

import com.zb.entity.TbQuotaModel;
import com.zb.service.TbQuotaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

@Component
public class Monitor {
    @Autowired
    private EmqClient emqClient;

    @Autowired
    private TbQuotaService tbQuotaService;

    @PostConstruct
    public void initSystem(){
        System.out.println("系统启动。。。。。");
        emqClient.connect();
        List<TbQuotaModel> list = tbQuotaService.list();
        list.forEach(item -> {
            emqClient.subscribe("$queue/"+item.getSubject());
        });

        System.out.println("订阅主题完毕");
    }
}
